// saveToDB.js
const db = require('./db');

async function saveNews(news) {
  const [result] = await db.execute(
    'INSERT INTO news (title, content, time, url) VALUES (?, ?, ?, ?)',
    [news.title, news.content, news.time, news.url]
  );
  return result.insertId;
}

async function saveImage(newsId, filename) {
  await db.execute(
    'INSERT INTO images (news_id, filename) VALUES (?, ?)',
    [newsId, filename]
  );
}

module.exports = { saveNews, saveImage };
